﻿#include "CheckableListWidget.h"

CheckableListWidget::CheckableListWidget(QWidget *parent)
    : FListWidget{parent}
{}

void CheckableListWidget::addItem(const QString &text, bool checked)
{
    QListWidgetItem* item = new QListWidgetItem(this);
    item->setCheckState(checked ? Qt::Checked : Qt::Unchecked);
    item->setText(text);
    QListWidget::addItem(item);
}

bool CheckableListWidget::isItemChecked(int row) const
{
    return item(row)->checkState() == Qt::Checked;
}

bool CheckableListWidget::isAllChecked() const
{
    for (int row = 0; row < count(); row++) {
        if (!isItemChecked(row)) {
            return false;
        }
    }
    return true;
}

void CheckableListWidget::setAllChecked(bool all)
{
    for (int i = 0; i < count(); i++) {
        item(i)->setCheckState(all ? Qt::Checked : Qt::Unchecked);
    }
}
